package Eyjafjalla.card.attack;

import Eyjafjalla.action.*;
import Eyjafjalla.card.AbstractEyjafjallaCard;
import Eyjafjalla.patch.MelodyPatch;
import Eyjafjalla.subscriber.MelodySubscriber;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.common.DamageRandomEnemyAction;
import com.megacrit.cardcrawl.actions.common.HealAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;

import java.util.ArrayList;

public class UrgentPresto_Eyjafjalla extends AbstractEyjafjallaCard implements MelodySubscriber {
    public static final String ID = "UrgentPresto_Eyjafjalla";
    private static final CardStrings cardStrings;


    public UrgentPresto_Eyjafjalla(){
        super(ID, cardStrings.NAME,1,cardStrings.DESCRIPTION,CardType.ATTACK,CardRarity.COMMON,CardTarget.ENEMY);
        this.baseDamage = 6;
        this.damage =6;
        this.baseMagicNumber = 4;
        this.magicNumber = 4;
        setFireDescription(cardStrings.EXTENDED_DESCRIPTION[0]);
    }

    @Override
    public void calculateCardDamage(AbstractMonster mo) {
        int trueD = baseDamage;
        if(isFire()){
            baseDamage+=2;
        }
        super.calculateCardDamage(mo);
        baseDamage = trueD;
        isDamageModified = baseDamage!=damage;
    }

    @Override
    public void applyPowers() {
        int trueD = baseDamage;
        if(isFire()){
            baseDamage+=2;
        }
        int trueM = baseMagicNumber;
        if(isFire()){
            baseMagicNumber+=2;
        }
        super.applyPowers();
        baseDamage = trueD;
        isDamageModified = baseDamage!=damage;
        magicNumber = baseMagicNumber;
        baseMagicNumber = trueM;
        isMagicNumberModified = baseMagicNumber!=magicNumber;
    }

    @Override
    public AbstractCard makeCopy() {
        return new UrgentPresto_Eyjafjalla();
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        addToBot(new EyjafjallaAttackAction());
        addToBot(new DamageAction(m,new DamageInfo(p,damage,damageTypeForTurn), AbstractGameAction.AttackEffect.SLASH_VERTICAL));
        addToBot(new MelodyAction(getSingle()));
    }

    public MelodyPatch.MelodySingle getSingle(){
        ArrayList<MelodyPatch.MelodyNote> notes = new ArrayList<>();
        notes.add(new MelodyPatch.MelodyNote(this,0,2,cardStrings.EXTENDED_DESCRIPTION[1]+this.magicNumber+cardStrings.EXTENDED_DESCRIPTION[2]));
        notes.add(new MelodyPatch.MelodyNote(this,1,1,cardStrings.EXTENDED_DESCRIPTION[1]+this.magicNumber+cardStrings.EXTENDED_DESCRIPTION[2]));
        notes.add(new MelodyPatch.MelodyNote(this,2,1,cardStrings.EXTENDED_DESCRIPTION[1]+this.magicNumber+cardStrings.EXTENDED_DESCRIPTION[2]));
        MelodyPatch.MelodySingle single = new MelodyPatch.MelodySingle(this.name,notes,null);
        return single;
    }

    @Override
    public ArrayList<AbstractGameAction> getNoteActions(boolean isFinal,int specialAmount) {
        ArrayList<AbstractGameAction> actions = new ArrayList<>();
        actions.add(new DamageRandomEnemyAction(new DamageInfo(AbstractDungeon.player,specialAmount, DamageInfo.DamageType.THORNS), AbstractGameAction.AttackEffect.SLASH_VERTICAL));
        return actions;
    }

    @Override
    public int initializeSpecialAmount(boolean isFinal) {
        return this.magicNumber;
    }

    @Override
    public void upgrade() {
        if(!this.upgraded){
            upgradeName();
            upgradeMagicNumber(2);
        }
    }

    static {
        cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    }
}


